#pragma once
#include<iostream>
#include<string>
#include<unordered_map>
#include<fstream>

const std::string dictname = "./data.txt";
const std::string sep = ":";

static bool Split(const std::string& s, std::string* part1, std::string* part2)
{
    auto pos = s.find(sep);
    if (pos == std::string::npos)
        return false;
    *part1 = s.substr(0, pos);
    *part2 = s.substr(pos + 1);
    return true;
}

class Init
{
public:
    Init()
    {
        std::ifstream in(dictname);
        if (!in.is_open())
        {
            std::cout << "isfstream failed" << std::endl;
            exit(1);
        }
        std::string line;
        while (getline(in, line))
        {
            std::string part1;
            std::string part2;
            Split(line, &part1, &part2);
            map.insert({ part1,part2 });
        }
        in.close();
    }

    std::string transaction(const std::string& key)
    {
        auto iter = map.find(key);
        if (iter == map.end())
        {
            return "Unknow";
        }
        return iter->second;
    }

private:
    std::unordered_map<std::string, std::string> map;
};